package com.iot.modbus.writer.impl;

import com.iot.modbus.writer.WriterSession;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.locator.BaseLocator;

import static com.serotonin.modbus4j.code.DataType.*;

public class SimpleWriterSession implements WriterSession {

    private ModbusMaster master;

    public SimpleWriterSession(ModbusMaster master) {
        this.master = master;
    }

    @Override
    public void writeInt16( int startOffset, Object values) throws ModbusTransportException, ErrorResponseException {

        master.setValue(BaseLocator.holdingRegister(1, 30, TWO_BYTE_INT_SIGNED),3333 );

    }

    @Override
    public void writeFloat32(int startOffset, Object values) throws ModbusTransportException, ErrorResponseException {
        master.setValue(BaseLocator.holdingRegister(1, 30, FOUR_BYTE_FLOAT_SWAPPED ),3 );
    }
}
